#include "base.h"
#include "unordered_map"
#include "unordered_set"

class Solution
{
public:
    double findMedianSortedArrays(vector<int> &nums1, vector<int> &nums2)
    {
        list<int> list;
        int i = 0, j = 0;
        while (i < nums1.size() && j < nums2.size())
        {
            //小数先出
            if (nums1[i] < nums2[j])
            {
                list.push_back(nums1[i]);
                i++;
            }
            else
            {
                list.push_back(nums2[j]);
                j++;
            }
        }
        while (i < nums1.size())
        {
            list.push_back(nums1[i]);
            i++;
        }
        while (j < nums2.size())
        {
            list.push_back(nums2[j]);
            j++;
        }
        if (list.size() % 2 == 0)
        {
            int i = 0;
            auto iter =
                list.begin();
            //长度为4
            while (i != (list.size() - 1) / 2)
            {
                iter++;
                i++;
            }
            auto a = *iter;
            iter++;
            auto b = *iter;
            return double(a + b) / 2;
        }
        else
        {
            int i = 0;
            auto iter =
                list.begin();
            while (i != (list.size() - 1) / 2)
            {
                iter++;
                i++;
            }
            auto a = *iter;
            return double(a);
        }
    }
};

void main()
{
    Solution sol;
    vector<int> a1 = {1, 2};
    vector<int> a2 = {3, 4};

    auto a = sol.findMedianSortedArrays(a1, a2);
}